/**
  * Author: Jordi Vilaplana Mayoral <jvilaplana@alumnes.udl.cat>
  * Date: 05/04/2011
  * 
  * LocationManager
  * Copyright (C) 2011 Jordi Vilaplana Mayoral
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * 
  * @(#)
  * Description: This program allows users to book rooms and schedule activities
  */

package locmanager.beans;

import java.io.Serializable;
import java.util.List;
import locmanager.persistence.DerbyPersistence;

public class LocationBean implements Serializable {

  private int locationId;
  private String publicName;
  private int roomTypeId;
  private String roomType;
  private int capacity;
  private List<EquipmentBean> equipments;

  public LocationBean() {
    this.locationId = -1;
    this.publicName = null;
    this.roomTypeId = -1;
    this.roomType = null;
    this.capacity = -1;
    this.equipments = null;
  }

  public LocationBean(int locationId, String publicName, int roomTypeId, int capacity) {
    this.locationId = locationId;
    this.publicName = publicName;
    this.roomTypeId = roomTypeId;
    this.capacity = capacity;
    this.roomType = getRoomTypeName();
  }

  public LocationBean(int locationId, String publicName, int roomTypeId, int capacity, List<EquipmentBean> equipments) {
    this.locationId = locationId;
    this.publicName = publicName;
    this.roomTypeId = roomTypeId;
    this.capacity = capacity;
    this.roomType = getRoomTypeName();
    this.equipments = equipments;
  }

  public int getCapacity() {
    return capacity;
  }

  public void setCapacity(int capacity) {
    this.capacity = capacity;
  }

  public int getLocationId() {
    return locationId;
  }

  public void setLocationId(int locationId) {
    this.locationId = locationId;
  }

  public String getPublicName() {
    return publicName;
  }

  public void setPublicName(String publicName) {
    this.publicName = publicName;
  }

  public int getRoomTypeId() {
    return roomTypeId;
  }

  public void setRoomTypeId(int roomTypeId) {
    this.roomTypeId = roomTypeId;
  }

  public String getRoomType() {
    return roomType;
  }

  public void setRoomType(String roomType) {
    this.roomType = roomType;
  }


  private String getRoomTypeName() {
    DerbyPersistence db = new DerbyPersistence();
    return db.getRoomType(this.roomTypeId);
  }

  public List<EquipmentBean> getEquipments() {
    return equipments;
  }

  public void setEquipments(List<EquipmentBean> equipments) {
    this.equipments = equipments;
  }

  public boolean hasEquipment(int equipmentId) {
    for(EquipmentBean equipment : this.equipments) {
      if(equipment.getEquipmentId() == equipmentId) return true;
    }
    return false;
  }
  

}
